<template>
  <el-menu router class="el-menu-vertical-demo" :default-active="route().fullPath" @open="handleOpen" @close="handleClose">

    <template v-for="item, index in MenuStore.getMenuList" :key="index">
      <el-menu-item v-if="item.menu_id == -1" :index="item.menu_href">
        <template #title>
          <el-icon>
            <component :is="item.menu_icon"></component>
          </el-icon>
          <span>{{ item.menu_text }}</span>
        </template>
      </el-menu-item>

      <el-sub-menu v-else :index="`${index}`">
        <template #title>
          <el-icon>
            <component :is="item.menu_icon"></component>
          </el-icon>
          <span>{{ item.menu_text }}</span>
        </template>



        <el-menu-item v-for="v, i in item.children" :index="'/admin/' + item.menu_href + v.menu_href">
          <template #title>
            <el-icon>
              <component :is="v.menu_icon"></component>
            </el-icon>
            <span>{{ v.menu_text }}</span>
          </template>
        </el-menu-item>

      </el-sub-menu>
    </template>



  </el-menu>
</template>

<script lang="ts" setup>

import http, { setItem, getItem, firstToUpper, createdRouterConfig } from "@/utils";
import { Menu } from "@/types/response/Menu";
import { useRouterAction } from "@/utils/router";
import { defaultMenu } from "@/router";
import { onMounted, reactive } from "vue";
const modules = import.meta.glob('@/views/admin/**/*.vue')
import { useMenuStore } from "@/state/menu";
const MenuStore = useMenuStore()
const { router, route } = useRouterAction()

const state: {
  menu: Menu[]
} = reactive({
  menu: []
})

onMounted(() => {
  console.log("menu------: ");
  getAllMenu();
})


const getAllMenu = async () => {
  await MenuStore.httpMenuList();
  if (router.getRoutes().length <= 12) {
    createdRouterConfig(router)
  }

}



const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>